package com.contory.ssn_lgnd.app.maingame;

import java.util.ArrayList;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.framework.math.Vector2;

public class PatrolMovePattern {
	ArrayList<Vector2> pointList;
	int desPtr = -1;
	Vector2 des = null;
	Vector2 dir;
	
	public PatrolMovePattern(){
		pointList = new ArrayList<Vector2>();
		dir = new Vector2();
	}
	
	public void setPoint(Vector2 point){
		pointList.add(point);
	}
	
	public void setPoints(ArrayList<Vector2> points, float vW, float vH){
		for(int i = 0; i < points.size(); i++){
			pointList.add(new Vector2(vW * points.get(i).x, vH * points.get(i).y));
			//Log.d("2", String.valueOf(pointList.get(i).x + ", " + pointList.get(i).y));
		}
		//Log.d("2", " ");
	}
	
	public boolean setReady(float strX, float strY){
		if(pointList.size() < 2){
			return false;
		}
		float dx = pointList.get(0).x;
		float dy = pointList.get(0).y;
		for(int i = 0; i < pointList.size(); i++){
			pointList.get(i).x = pointList.get(i).x - dx + strX;
			pointList.get(i).y = pointList.get(i).y - dy + strY;
		}
		des = pointList.get(1);
		dir.set(des.x - pointList.get(0).x, des.y - pointList.get(0).y);
		desPtr = 1;
		return true;
	}
	
	public void setNext(){
		Vector2 str = pointList.get(desPtr++);
		if(desPtr >= pointList.size())
			desPtr = 0;
		des = pointList.get(desPtr);
		dir.set(des.x - str.x, des.y - str.y);
	}
	
	public Vector2 getDir(){
		return dir;
	}
	
	public Vector2 getDes(){
		return des;
	}
}
